package echat.future.cn.echat.my.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.databinding.ActivityRemindUserListBinding;
import echat.future.cn.echat.my.adapter.RemindUserAdapter;
import echat.future.cn.echat.my.api.UserApi;
import echat.future.cn.echat.my.bean.PlanList;
import echat.future.cn.echat.my.bean.RemindUserBean;
import echat.future.cn.echat.my.utils.HttpUtilsRequst;
import echat.future.cn.echat.my.utils.StatusBarUtils;
import echat.future.cn.echat.my.utils.UserHelper;
import echat.future.cn.echat.my.weight.Navagation.IBaseNavagation;

public class RemindUserListActivity extends BaseActivity<ActivityRemindUserListBinding>{

    RemindUserAdapter remindUserAdapter;

    private List<RemindUserBean> datas = new ArrayList<>();

    @Override
    public int layoutId() {
        return R.layout.activity_remind_user_list;
    }

    @Override
    public IBaseNavagation navagation() {
        return null;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtils.hideStatus(this);
    }

    @Override
    public void initView() {
        remindUserAdapter = new RemindUserAdapter(datas);
        bind.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        bind.recyclerView.setAdapter(remindUserAdapter);
        bind.divingList.setOnClickListener(v->startActivity(new Intent(this,DivingListActivity.class)));
        load(page);
        remindUserAdapter.setOnLoadMoreListener(() -> {
            page++;
            load(page);
        },bind.recyclerView);
    }
    private int page = 1;

    private void load(int page){
        new HttpUtilsRequst<PlanList>(this,HttpUtilsRequst.retrofitClient.create(UserApi.class).planList(UserHelper.getToken(),String.valueOf(page)))
                .setmOnRequstSuccessListener((HttpUtilsRequst.OnRequstSuccessListener<PlanList>) planList -> {
                    if(page == 1){
                        datas.clear();
                    }
                    remindUserAdapter.loadMoreComplete();
                    bind.all.setText(planList.getList_user_num()+"人");
                    bind.recharge.setText("0人");
                    if(planList.getList_user() == null || planList.getList_user().isEmpty()){
                        remindUserAdapter.loadMoreEnd();
                        return;
                    }
                    datas.addAll(planList.getList_user());
                    remindUserAdapter.notifyDataSetChanged();
                    if(planList.getList_user().size() <10){
                        remindUserAdapter.loadMoreEnd();
                    }
                })
                .start();
    }

}
